package com.qfedu.edu.iotserver.controller;


import com.qfedu.edu.iotserver.service.OrderService;
import com.qfedu.edu.pojo.Order;
import com.qfedu.edu.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaobobo
 * @since 2024-09-25
 */
@RestController
@RequestMapping("/iotserver/order")
@Api(description = "订单模块",tags = "订单模块")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 添加订单
     * @param order
     * @return
     */
    @PostMapping("add")
    @ApiOperation("添加订单")
    @ApiImplicitParam(name = "token", value = "用户令牌", required = true, dataType = "string", paramType = "header")
    @Secured("ROLE_admin")
    public R add(@RequestBody Order order){
        orderService.add(order);
        return R.ok();
    }


    /**
     * 通过订单号查询订单的状态
     * @param orderNumber
     * @return
     */
    @GetMapping("/getOrderStatus/{orderNumber}")
    @ApiOperation("通过订单号获取订单状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "用户令牌", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "orderNumber", value = "订单号", required = true, dataType = "string", paramType = "path")
    })
    public R getOrderStatus(@PathVariable("orderNumber") String orderNumber){
        Integer status=orderService.getOrderStatus(orderNumber);
        return R.ok().data("orderStatus",status);
    }

}

